/*
 * cmd.h
 *
 *  Created on: 08.02.2012
 *      Author: Roma Jam
 */

#include "stm32f10x.h"

#ifndef CMD_H_
#define CMD_H_

#define cmd_get         '1'
#define cmd_set         '2'
#define cmd_reset       '3'
#define ATR             "Quit from 'Setup Mode'.\r"

#define lengh_of_cmd    9
#define number_of_cmd   12

#define az_lengh        3
#define el_lengh        2
//#define

class cmd_t {
private:
public:
    void Reset(void);
    void Terminal_Process_Byte(uint8_t Byte);
    void Terminal_Angle_Setup(uint8_t Byte);
    void Terminal_Process_Cmd(void);
    void Terminal_Process_Cmd_Event(uint8_t Apointer);
    void LabServer_Process_Byte(uint16_t Byte);
    void Clear_buffer(void);
    void Get_Parametres(void);
    void Set_Parametres(void);
    void Set_Angles(const uint16_t new_azimuth, const uint16_t new_elevation);

};
extern cmd_t CMD;

const uint8_t array_of_cmd[number_of_cmd][lengh_of_cmd] = {
        {'S','h','o','w','A','n','g','l','e'},
        {'M','o','d','e','S','e','t','u','p'},
        {'C','h','a','n','n','e','l','0','1'},
        {'C','h','a','n','n','e','l','0','2'},
        {'M','o','t','o','r','U','p','O','n'},
        {'M','o','t','o','r','U','p','O','f'},
        {'M','o','t','o','r','D','n','O','n'},
        {'M','o','t','o','r','D','n','O','f'},
        {'M','o','t','o','r','L','t','O','n'},
        {'M','o','t','o','r','L','t','O','f'},
        {'M','o','t','o','r','R','t','O','n'},
        {'M','o','t','o','r','R','t','O','f'},

};

struct cmdvariables_t {
    /* Setup command array and counters */
    uint8_t counter, string;
    bool cmd_detect;
    uint32_t cmd_detect_tmr;
    uint8_t cmd_to_start, cmd_byte, pointer;
    uint8_t Arr[lengh_of_cmd];
    /* Setup angles arrays and counters */
    uint8_t az_counter, el_counter;
    uint8_t azimuth_Arr[az_lengh], elevation_Arr[el_lengh];
};
extern struct cmdvariables_t CMD_Var;

struct angle_flag_t {
    bool azimuth_set, elevation_set, el_dec, az_full, el_full;
};
extern angle_flag_t angle_flag;

enum cmd_flag_t {
    reset, get_parametres, set_parametres, free
};
extern cmd_flag_t cmd_flag;

#endif /* CMD_H_ */
